#ifndef __LOADER_H_
#define __LOADER_H_

/*
 * Memory layout:
 *  +-----+-----+----+-----+-----+-------+------+-----+----------+-----+----+------+
 *  | IDT | GDT | pd | pth | ptl | kernel stack | inf | Reserved | ptk | bm | other|
 *  +-----+-----+----+-----+-----+-------+------+-----+----------+-----+----+------+
 *  0    2K    4K   8K    12K   16K          9F000  9FC00       1M     ?    ?    MAX
 *
 *  IDT - re-initilized at kernel for protected mode.
 *  GDT - has been initilized at loader.asm.
 *  pd  - page directory. Used in loader.asm, and in kernel for init process.
 *  pth - kernel's page table high address(3G ~ 3G+4M).
 *        Reused as dynamic map page table in kernel.
 *  ptl - kernel's page table low address(0 ~ 4M).
 *  kernel, stack -
 *  inf - hardware infomation passed to kenerl.
 *  Reserved -
 *  ptk - kernel's new page tables. The size is decieded by the memory' size.
 *  bm  - memory managment's bitmap. The size is decieded by the memory' size.
 *  other -
 *
 *  See mm.c for more details.
 */

/* ======================================== */
/*       Specified in boot/loader.asm       */
/* ======================================== */

/* Offset of kernel in virtual memory. */
#define VIR_KERNEL	0xC0000000
#define PHY2LIN(phy)	((u32_t)(phy) + VIR_KERNEL)

/* Information area. */
#define PHY_ADDR_INFO_DISK		0x9F000 // disk
#define PHY_ADDR_INFO_MEMORY_NUM	0x9F020 // number of memory infor area
#define PHY_ADDR_INFO_MEMORY		0x9F024 // memory information

/* Address of IDT and GDT. */
#define PHY_ADDR_IDT			0
#define PHY_ADDR_GDT			0x800

/* Address of page-directory and page-tables. */
#define PHY_ADDR_PAGE_DIR		0x1000
#define PHY_ADDR_PAGE_TABLE_HIGH	0x2000
#define PHY_ADDR_PAGE_TABLE_LOW		0x3000


/* ======================================== */
/*            Used by kernel.               */
/* ======================================== */

#define INFO_DISK		(PHY_ADDR_INFO_DISK + VIR_KERNEL)
#define INFO_MEMORY_NUM		(PHY_ADDR_INFO_MEMORY_NUM + VIR_KERNEL)
#define INFO_MEMORY		(PHY_ADDR_INFO_MEMORY + VIR_KERNEL)

/* Address of IDT and GDT. */
#define ADDR_IDT		(PHY_ADDR_IDT + VIR_KERNEL)
#define ADDR_GDT		(PHY_ADDR_GDT + VIR_KERNEL)

/* Address of page-directory and page-tables. */
#define KERNEL_PAGE_DIR		(PHY_ADDR_PAGE_DIR + VIR_KERNEL)
#define KERNEL_PAGE_TABLE_HIGH	(PHY_ADDR_PAGE_TABLE_HIGH + VIR_KERNEL)
#define KERNEL_PAGE_TABLE_LOW	(PHY_ADDR_PAGE_TABLE_LOW + VIR_KERNEL)

/* New kernel page tables. */
#define PHY_ADDR_PAGE_TABLES	0x100000
#define KERNEL_PAGE_TABLES	(PHY_ADDR_PAGE_TABLES + VIR_KERNEL)

#endif /* __LOADER_H_ */
